package com.yx.server.controller;

import com.yx.server.facade.IUserFacade;
import com.yx.server.util.PageResultUtil;
import com.yx.server.util.ResultUtil;
import com.yx.server.pojo.User;
import com.yx.server.query.UserQueryLink;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("/user")
public class UserController {

    @Resource
    private IUserFacade userFacade;

    @ResponseBody
    @RequestMapping("/list")
    public ResultUtil user(UserQueryLink query) {
        PageResultUtil<User> paging = userFacade.queryPage(query);
        return ResultUtil.newInstance().setData(paging);
    }

    @ResponseBody
    @RequestMapping("/user")
    public ResultUtil user(Long id) {
        if (null == id){
            return ResultUtil.newInstance().setMessage("User is empty!").setStatus(ResultUtil.FAILED);
        }
        User user = userFacade.findByPrimaryKey(id);
        return ResultUtil.newInstance().setData(user);
    }
}
